package cn.findviewbydream.evil.main.controller;

import cn.findviewbydream.evil.main.entity.BaseTypeOfWorkEntity;
import cn.findviewbydream.evil.main.entity.EmployeeEntity;
import cn.findviewbydream.evil.main.service.SettingEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/********************************************
 * 工程名：MealOrder
 * 包名：cn.findviewbydream.evil.main.controller
 * 时间：17-2-21
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：设置界面->员工信息
 ********************************************/
@Controller
public class SettingEmployeeController
{
    private final SettingEmployeeService service;

    @Autowired
    public SettingEmployeeController(SettingEmployeeService settingEmployeeService)
    {
        this.service = settingEmployeeService;
    }

    @RequestMapping("/setting/employee")
    public String index()
    {
        return "setting/employee";
    }

    @RequestMapping("/setting/employee/get/list")
    @ResponseBody
    public List<EmployeeEntity> getEmployeeList(boolean isAll)
    {
        return service.getEmployeeList(isAll);
    }

    @RequestMapping("/setting/employee/get")
    @ResponseBody
    public EmployeeEntity getEmployee(String id)
    {
        return service.getEmployee(id);
    }

    @RequestMapping("/setting/employee/get/typeofwork/list")
    @ResponseBody
    public List<BaseTypeOfWorkEntity> getTypeOfWorkList()
    {
        return service.getTypeOfWorkList();
    }

    /**
     * 新增员工
     *
     * @return 新员工Id（工号）
     */
    @RequestMapping(value = "/setting/employee/post/new", method = RequestMethod.POST)
    @ResponseBody
    public String postNewEmployee(@RequestParam(required = false) String employeeId,
                                  String name,
                                  int typeOfWorkId,
                                  int salary,
                                  @RequestParam(required = false) Integer bonus,
                                  @RequestParam(required = false) Date entryDateTime,
                                  @RequestParam(required = false) Date leaveDateTime)
    {
        return service.postNewEmployee(employeeId, name, typeOfWorkId,
                salary, bonus, entryDateTime, leaveDateTime);
    }

    @RequestMapping(value = "/setting/employee/post", method = RequestMethod.POST)
    @ResponseBody
    public boolean postEmployee(String employeeId,
                                String name,
                                int typeOfWorkId,
                                int salary,
                                @RequestParam(required = false)Integer bonus,
                                @RequestParam(required = false) Date entryDateTime,
                                @RequestParam(required = false)Date leaveDateTime)
    {
        return service.postEmployee(employeeId, name, typeOfWorkId,
                salary, bonus, entryDateTime, leaveDateTime);
    }

    /**
     * 员工离职
     *
     * @return 离职时间
     */
    @RequestMapping(value = "/setting/employee/post/leave", method = RequestMethod.POST)
    @ResponseBody
    public String postEmployeeLeave(String employeeId)
    {
        return service.postEmployeeLeave(employeeId);
    }

}
